package com.dq.domain.brand;

import com.dq.vo.baseVo.VO;
import com.dq.domain.base.BaseEntity;
import com.dq.domain.sys.section.SysSection;
import com.dq.utils.TimeUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.Entity;
import javax.persistence.ManyToOne;

/**
 * @创建人 gewenzhen
 * @创建时间 2019/9/16
 * @描述
 */
@Data
@Entity
@ApiModel(value = "品牌")
public class Brand extends BaseEntity implements VO.ToVO {
    @ApiModelProperty(value = "名称")
    protected String name;
    @ApiModelProperty(value = "介绍")
    protected String simpleDesc;
    @ApiModelProperty(value = "logo")
    protected String logoImgUrl;
    @ApiModelProperty(value = "列表图")
    protected String listImgUrl;
    @ApiModelProperty(value = "排序")
    protected Long sortNo;
    @ApiModelProperty(value = "机构", hidden = true)
    @ManyToOne
    protected SysSection org;


    @Data
    @ApiModel(value = "品牌视图")
    public static class Vo implements VO {
        @ApiModelProperty("id")
        private Long id;
        @ApiModelProperty(value = "名称")
        private String name;
        @ApiModelProperty(value = "介绍")
        private String simpleDesc;
        @ApiModelProperty(value = "logo")
        private String logoImgUrl;
        @ApiModelProperty(value = "列表图")
        private String listImgUrl;
        @ApiModelProperty(value = "排序")
        private Long sortNo;
        @ApiModelProperty("机构名称")
        private String orgName;
        @ApiModelProperty("机构id")
        private Long orgId;
        @ApiModelProperty("创建时间")
        private String createTime;
    }
    @Data
    @ApiModel(value = "品牌视图")
    public static class SmallBrandVo {
        @ApiModelProperty("id")
        protected Long id;
        @ApiModelProperty("品牌名称")
        protected String name;
        @ApiModelProperty("品牌logo")
        protected String imgUrl;
    }

    public SmallBrandVo toSmallBrandVo(){
        Brand.SmallBrandVo smallBrandVo = new Brand.SmallBrandVo();
        smallBrandVo.id = this.id;
        smallBrandVo.name = this.name;
        smallBrandVo.imgUrl = this.listImgUrl;
        return smallBrandVo;
    }

    @Override
    public VO toVO(boolean isRecursion) {
        Vo vo = new Vo();
        vo.id=this.id;
        vo.name = this.name;
        vo.simpleDesc = this.simpleDesc;
        vo.logoImgUrl = this.logoImgUrl;
        vo.listImgUrl = this.listImgUrl;
        vo.sortNo = this.sortNo;
        vo.orgName = this.org == null ? "" : this.org.getSimpleName();
        vo.orgId = this.org == null ? null : this.org.getId();
        vo.createTime = fmt(this.createTime, TimeUtil.YYYY_MM_DD_HH_MM_SS);
        return vo;
    }


}
